<template>
  <div class="main-bg">
    <el-tabs v-model="activeName">
      <el-tab-pane label="我的收藏" name="first">
        <div class="report-list" v-loading="loading">
          <div
            class="report-list-item"
            v-for="item in list"
            :key="item.id"
            @click="toDetail(item)"
          >
            <div class="report-list-item-header" style="cursor: pointer">
              <img
                class="report-list-item-header-icon"
                v-if="item.item_type == 3"
                src="@/assets/images/pdf-icon.png"
              />
              <span>{{ item.name }}</span>
            </div>
            <div class="report-list-item-info">
              <div
                class="report-list-item-info-list"
                v-if="item.item_type == 3"
              >
                <img
                  class="report-list-item-info-list-new"
                  src="@/assets/images/new.png"
                  v-if="item.is_new == 1"
                  alt=""
                />
                <!-- <div class="report-list-item-info-list-read">{{item.read_count}}人阅读</div> -->
                <div class="report-list-item-info-list-date">
                  上传于{{ item.timeText }}
                </div>
                <div class="report-list-item-info-list-page">
                  {{ item.page_count }}页
                </div>
              </div>
              <div
                class="report-list-item-info-list"
                v-if="item.item_type == 2"
              >
                <div class="report-list-item-info-list-read">文件夹</div>
                <div class="report-list-item-info-list-page">
                  {{ item.page_count }}份文档
                </div>
                <div class="report-list-item-info-list-date">
                  创建于{{ item.timeText }}
                </div>
              </div>
            </div>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
    <div class="report-page">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size.sync="currentPageSize"
        :current-page.sync="data.page"
        :total="listTotal"
        @current-change="pageChange"
      >
      </el-pagination>
    </div>
    <share v-model="shareModal" :fid="shareFid"></share>
  </div>
</template>

<script>
import { detailsCount } from "@/api/report.js";
import storage from "@/utils/storage";
import { myFavorite } from "@/api/login.js";
import { mapGetters } from "vuex";
import { shareFile } from "@/api/share.js";
import addGroup from "@/components/addGroup.vue";
import share from "@/components/share.vue";
export default {
  data() {
    return {
      shareModal: false,
      shareFid: "",
      data: {
        sid: "",
        page: 1,
        only_chart: "",
      },
      listTotal: 0,
      list: [],
      currentPageSize: 0,
      activeName: "first",
      lookDataChat: false,
      infoImg: "",
      infoImgList: [],
      chatName: "",
      listIndex: 0,
      loading: false,
    };
  },
  created() {
    this.data.sid = this.sid;
    this.getData();
  },
  components: { addGroup, share },
  computed: {
    ...mapGetters(["sid"]),
  },
  watch: {
    activeName: function (n, o) {
      if (n == "first") {
        this.data.only_chart = "";
        this.data.page = 1;
        this.getData();
      }
      if (n == "second") {
        this.data.only_chart = 1;
        this.data.page = 1;
        this.getData();
      }
    },
  },
  methods: {
    getData() {
      this.list = [];
      this.loading = true;
      myFavorite(this.data).then((res) => {
        this.list = res.data.items;
        this.listTotal = res.data.total;
        this.currentPageSize = res.data.page_size;
        this.loading = false;
      });
    },

    share(item) {
      this.shareFid = item.fid || item.id;
      this.shareModal = true;
    },
    pageChange(page) {
      this.data.page = page;
      this.getData();
      document.body.scrollTop = 0;
      document.documentElement.scrollTop = 0;
    },
    toDetail(item) {
      if (item.item_type == 2) {
        this.saveState();
        this.saveToBreadCrumb(item);
        this.dirParams.page = 1;
        this.currentPage = 1;
        this.dirParams.parent_id = item.item_id;
        this.getDataByFolder();
      }
      if (item.item_type == 3) {
        storage.set("report", JSON.stringify(item));
        this.$store.commit("createReport", storage.get("report"));

        // detailsCount()
        //   .then((res) => {
        const { Base64 } = require("js-base64");
        let { href } = this.$router.resolve({
          path: "/detail?fid=" + Base64.encode(item.id),
        });
        window.open(href, "_blank");
        // window.open("/PDF/web/viewer.html?file=" + item.online_url);
        // })
        // .catch((err) => {
        //   this.loading = false;
        // });
      }
    },
    lookChat(info, item, index) {
      this.infoImg = info.online_url;
      this.infoImgList = item.chart_list;
      this.chatName = item.name;
      this.listIndex = index;
      this.lookDataChat = true;
    },
  },
};
</script>

<style lang='less' scoped>
.main-bg {
  width: 720px;
  margin: 0 auto;
  padding-top: 60px;
  min-height: 650px;
}
.report {
  width: 720px;
  margin: 0 auto;
  min-height: 500px;
  &-search {
    margin: 40px 0;
    /deep/ .el-input-group__append {
      background: #467dd0;
      color: #fff;
      width: 96px;
    }
  }
  &-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    &-title {
      font-size: 16px;
      color: #3f4750;
      cursor: pointer;
      // font-weight: bold;
    }
    &-tag {
      &-item {
        margin-left: 8px;
      }
    }
  }
  &-list {
    position: relative;
    display: flex;
    justify-content: flex-start;
    align-items: stretch;
    flex-wrap: wrap;
    padding-top: 14px;
    padding-bottom: 20px;
    &-item {
      padding: 16px 20px 16px;
      width: 100%;
      background: #fff;
      border-radius: 2px;
      border: 1px solid rgba(233, 235, 238, 1);
      margin-top: 12px;
      &-header {
        display: flex;
        justify-content: flex-start;
        align-items: flex-start;
        font-size: 16px;
        line-height: 22px;
        &-icon {
          width: 16px;
          height: 16px;
          display: block;
          margin-top: 4px;
          margin-right: 6px;
        }
      }
      &-info {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 15px;
        &-list {
          display: flex;
          justify-content: flex-start;
          align-items: center;
          font-size: 14px;
          color: #8e969d;
          &-new {
            height: 24px;
            display: block;
            margin-right: 5px;
            width: 24px;
          }
          &-read,
          &-date,
          &-page,
          &-chat {
            margin-right: 20px;
          }
        }
        &-action {
          display: flex;
          justify-content: flex-end;
          align-items: center;
          &-item {
            width: 24px;
            height: 24px;
            display: block;
            margin-left: 16px;
          }
        }
      }
      &-img {
        margin-top: 19px;
        display: flex;
        justify-items: flex-start;
        align-items: center;
        &-item {
          width: 163px;
          height: 163px;
          display: block;
          margin-left: 12px;
          border-radius: 2px;
          display: flex;
          justify-items: center;
          align-items: center;
          &:first-child {
            margin-left: 0;
          }
          img {
            max-width: 100%;
            max-height: 100%;
            display: block;
          }
        }
      }
    }
  }
  &-page {
    width: 100%;
    padding: 15px 0;
    text-align: center;
  }
}
</style>